package xyz.xtt.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import xyz.xtt.admin.request.AssetAccountRecordReqest;
import xyz.xtt.admin.request.AssetAccountRequest;
import xyz.xtt.admin.service.IAssetAccountService;
import xyz.xtt.admin.utils.PageUtilV2;
import xyz.xtt.admin.vo.AssetAccountVo;
import xyz.xtt.admin.vo.AssetTransationRecordVo;
import xyz.xtt.common.response.ApiResult;

import java.util.List;

/**
 * <p>
 * 资产帐户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-17
 */
@RestController
@RequestMapping("/api/admin/asset_account")
public class AssetAccountController {

    @Autowired
    private IAssetAccountService assetAccountService;

    @Autowired
    private PageUtilV2 pageUtilV2;


    @GetMapping("/list")
    public ApiResult<Page<AssetAccountVo>> getList(AssetAccountRequest assetAccountRequest) {
        assetAccountRequest.setCurrent(pageUtilV2.getCurrent(assetAccountRequest.getCurrent()));
        assetAccountRequest.setPageSize(pageUtilV2.getPageSize(assetAccountRequest.getPageSize()));
       return ApiResult.ok(assetAccountService.getList(assetAccountRequest));
    }

    @GetMapping("/set_status")
    public ApiResult<Boolean> setState(@Validated @NotBlank(message = "id 不能为空") String id, Integer status) {
        Long Lid = Long.valueOf(id);
        return ApiResult.ok(assetAccountService.setState(Lid, status));
    }

    @GetMapping("/get_record_list")
    public ApiResult<Page<AssetTransationRecordVo> > getRecordList(AssetAccountRecordReqest req) {
        req.setCurrent(pageUtilV2.getCurrent(req.getCurrent()));
        req.setPageSize(pageUtilV2.getPageSize(req.getPageSize()));
        return  ApiResult.ok(assetAccountService.getRecordList(req));
    }
}
